/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ece496.pkg496_spu;

/** 
 *
 * @author Yiwen Su
 */
public class battery {
    public int battery (double mon_volt) {
    	//math_utils math_utils = new math_utils();
        double perc = 0;
        double zener = 6.19;
        double low = 6.4;
        
        perc = mon_volt - (low - zener);
        
        //mon_volt is read through IOIO board's PIN38
        //Low battery at 6.4V
        //Zener diode rated at 6.19V
        //Lowest allowable drop through Zener diode is 0.21V
        //Nominal battery level is at 7.4V, Percentage = 1.21 - 0.21 = 1, if overcharged, set at 1
        //Lowest battery level is at 6.4V, Percentage = 0.21 - 0.21 = 0, if undercharged, set at 0 and warn user
        
        if (perc >= 1) {
        	perc = 100;
        } else if (perc < 0){
        	perc = 0;
        } else {
        	perc = 100*perc;
        }
        
        int perc_out = (int) (perc);
        
        return perc_out;
    }
}